package org.ligson.org;

import com.netflix.loadbalancer.IRule;
import feign.Retryer;
import org.ligson.org.util.MyWeightedResponseTimeRule2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.web.client.RestTemplate;

import static java.util.concurrent.TimeUnit.SECONDS;

@SpringBootApplication
@EnableEurekaClient
//@EnableRetry
@EnableFeignClients
public class OrgApplication {
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    @Scope("prototype")
    public IRule iRule() {
        return new MyWeightedResponseTimeRule2();
    }

    //https://blog.csdn.net/zyt807/article/details/80553666
    @Bean
    public Retryer retryer() {
        //return new Retryer.Default(30, SECONDS.toMillis(10), 1);
        return new Retryer.Default();
    }

    public static void main(String[] args) {
        SpringApplication.run(OrgApplication.class, args);
    }
}
